<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>

        // 每一个对象都有一个属性  constructor  记录我是谁创建出来的

        const arr = [1, 2, 3];
        console.log(arr.constructor === Array);

        const str = new String('hi');
        console.log(str.constructor === String);

        const d = new Date();
        console.log(d.constructor);


        console.log(typeof arr);
        console.log(typeof str);
        console.log(typeof d);


        // typeof  只能用来判断基本数据类型
        // constructor  可以判断引用数据类型

        console.log(myType(arr));

        function myType(a) {
            if (typeof a === 'number') {
                return 'number'
            }
            if (typeof a === 'string') {
                return 'string'
            }
            if (typeof a === 'undefined') {
                return 'undefined'
            }
            if (typeof a === 'object') {
                if (a.constructor === Array) {
                    return 'array'
                }
                if (a.constructor === Date) {
                    return 'date'
                }
                if (a.constructor === Object) {
                    return 'object'
                }

            }

        }

    </script>

</body>

</html>